<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>五指山污水处理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/huazhi/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/huazhi/css/public.css" media="all">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/css/logincss/layout.css" media="all">
    <link rel="shortcut icon" href="<%=request.getContextPath()%>/huazhi/images/favicon.ico"/>
    <link rel="stylesheet" href="<%=request.getContextPath()%>/huazhi/css/formSelects-v4.css" media="all">
</head>
<style>
    /* 底部固定区域 */
    .layui-layout-admin .layui-footer {
        padding: 10px 0;
        text-align: center;
    }

    .layui-layout-admin .layui-footer {
        background-color: #fff;
    }
</style>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form" lay-filter="component-form-element" id="form" method="post" enctype="multipart/form-data">
                <div class="layui-tab layui-tab-brief">
                    <ul class="layui-tab-title">
                        <li class="layui-this">基本信息</li>
                        <li>文件信息</li>
                        <li>检测指标</li>
                        <li>检测类别</li>
                    </ul>
                    <div class="layui-tab-content" style="height: auto">
                        <div class="layui-tab-item layui-show">
                            <div class="layui-form-item">
                                <div class="layui-col-lg6">
                                    <div class="layui-col-xs11">
                                        <label class="layui-form-label">村名:</label>
                                        <div class="layui-input-block">
                                            <div class="layui-form" lay-filter="village">
                                                <select name="cun" id="village" lay-verify="village" lay-filter="villageselect" lay-search>
                                                    <option value="">请选择</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-col-xs1">
                                        <div class="layui-form-mid layui-word-aux"
                                             style="color: red !important;padding: 10px !important;">*
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-col-lg6">
                                    <div class="layui-col-xs11">
                                        <label class="layui-form-label">检查人</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="operator" lay-verify="operator"
                                                   autocomplete="off" placeholder="请输入检查人名称"
                                                   class="layui-input" style="padding-right: 30px;">
                                        </div>
                                    </div>
                                    <div class="layui-col-xs1">
                                        <div class="layui-form-mid layui-word-aux"
                                             style="color: red !important;padding: 10px !important;">*
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-col-lg6">
                                    <div class="layui-col-xs11">
                                        <label class="layui-form-label">检查时间:</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="checktime" id="checktime"
                                                   autocomplete="off" class="layui-input" readonly="readonly" lay-verify="checktime">
                                        </div>
                                    </div>
                                    <div class="layui-col-xs1">
                                        <div class="layui-form-mid layui-word-aux"
                                             style="color: red !important;padding: 10px !important;">*
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-col-lg6">
                                    <div class="layui-col-xs3" id="file">
                                        <label class="layui-form-label">档案文件</label>
                                        <span class="layui-btn layui-btn-primary">选择文件
                                            <input lay-verify="file" type="file" id="changefile" class="uploadImg" name="uploadFile" multiple="multiple">
                                        </span>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-tab-item">
                            <table class="layui-hide" id="files" lay-filter="filesTables"></table>
                            <div id="laypage"></div>
                        </div>
                        <div class="layui-tab-item">
                            <div class="layui-form-item">
                                <div class="layui-col-lg6">
                                    <div class="layui-col-xs11">
                                        <label class="layui-form-label">流量</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="flow" lay-verify="flow"
                                                   autocomplete="off" placeholder="请输入流量"
                                                   class="layui-input" style="padding-right: 30px;">
                                        </div>
                                    </div>
                                    <div class="layui-col-xs1">
                                        <div class="layui-form-mid layui-word-aux"
                                             style="color: red !important;padding: 10px !important;">*
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-col-lg6">
                                    <div class="layui-col-xs11">
                                        <label class="layui-form-label">pH值</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="ph" lay-verify="ph"
                                                   autocomplete="off" placeholder="请输入pH值"
                                                   class="layui-input" style="padding-right: 30px;">
                                        </div>

                                    </div>
                                    <div class="layui-col-xs1">
                                        <div class="layui-form-mid layui-word-aux"
                                             style="color: red !important;padding: 10px !important;">*
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-col-lg6">
                                    <div class="layui-col-xs11">
                                        <label class="layui-form-label">DO</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="do" lay-verify="do"
                                                   autocomplete="off" placeholder="请输入DO"
                                                   class="layui-input" style="padding-right: 30px;">
                                        </div>
                                    </div>
                                    <div class="layui-col-xs1">
                                        <div class="layui-form-mid layui-word-aux"
                                             style="color: red !important;padding: 10px !important;">*
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-col-lg6">
                                    <div class="layui-col-xs11">
                                        <label class="layui-form-label">透明度</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="transparency" lay-verify="transparency"
                                                   autocomplete="off" placeholder="请输入透明度"
                                                   class="layui-input" style="padding-right: 30px;">
                                        </div>
                                    </div>
                                    <div class="layui-col-xs1">
                                        <div class="layui-form-mid layui-word-aux"
                                             style="color: red !important;padding: 10px !important;">*
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-col-lg6">
                                    <div class="layui-col-xs11">
                                        <label class="layui-form-label">SS</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="ss" lay-verify="ss"
                                                   autocomplete="off" placeholder="请输入SS"
                                                   class="layui-input" style="padding-right: 30px;">
                                        </div>
                                    </div>
                                    <div class="layui-col-xs1">
                                        <div class="layui-form-mid layui-word-aux"
                                             style="color: red !important;padding: 10px !important;">*
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-col-lg6">
                                    <div class="layui-col-xs11">
                                        <label class="layui-form-label">CODcr</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="codcr" lay-verify="codcr"
                                                   autocomplete="off" placeholder="请输入CODcr"
                                                   class="layui-input" style="padding-right: 30px;">
                                        </div>
                                    </div>
                                    <div class="layui-col-xs1">
                                        <div class="layui-form-mid layui-word-aux"
                                             style="color: red !important;padding: 10px !important;">*
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-col-lg6">
                                    <div class="layui-col-xs11">
                                        <label class="layui-form-label">BOD5</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="bod5" lay-verify="bod5"
                                                   autocomplete="off" placeholder="请输入BOD5"
                                                   class="layui-input" style="padding-right: 30px;">
                                        </div>
                                    </div>
                                    <div class="layui-col-xs1">
                                        <div class="layui-form-mid layui-word-aux"
                                             style="color: red !important;padding: 10px !important;">*
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-col-lg6">
                                    <div class="layui-col-xs11">
                                        <label class="layui-form-label">TP</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="tp" lay-verify="tp"
                                                   autocomplete="off" placeholder="请输入TP"
                                                   class="layui-input" style="padding-right: 30px;">
                                        </div>
                                    </div>
                                    <div class="layui-col-xs1">
                                        <div class="layui-form-mid layui-word-aux"
                                             style="color: red !important;padding: 10px !important;">*
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-col-lg6">
                                    <div class="layui-col-xs11">
                                        <label class="layui-form-label">TN</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="tn" lay-verify="tn"
                                                   autocomplete="off" placeholder="请输入TN"
                                                   class="layui-input" style="padding-right: 30px;">
                                        </div>
                                    </div>
                                    <div class="layui-col-xs1">
                                        <div class="layui-form-mid layui-word-aux"
                                             style="color: red !important;padding: 10px !important;">*
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-col-lg6">
                                    <div class="layui-col-xs11">
                                        <label class="layui-form-label">HN3-N</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="hn3N" lay-verify="hn3N"
                                                   autocomplete="off" placeholder="请输入HN3-N"
                                                   class="layui-input" style="padding-right: 30px;">
                                        </div>
                                    </div>
                                    <div class="layui-col-xs1">
                                        <div class="layui-form-mid layui-word-aux"
                                             style="color: red !important;padding: 10px !important;">*
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-tab-item">
                            <div class="layui-form-item">
                                <div class="layui-col-lg6">
                                    <div class="layui-col-xs11">
                                        <label class="layui-form-label">水量</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="yield" lay-verify="yield"
                                                   autocomplete="off" placeholder="请输入水量"
                                                   class="layui-input" style="padding-right: 30px;">
                                        </div>
                                    </div>
                                    <div class="layui-col-xs1">
                                        <div class="layui-form-mid layui-word-aux"
                                             style="color: red !important;padding: 10px !important;">*
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-col-lg6">
                                    <div class="layui-col-xs11">
                                        <label class="layui-form-label">进水浓度</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="iconcentration" lay-verify="iconcentration"
                                                   autocomplete="off" placeholder="请输入进水浓度"
                                                   class="layui-input" style="padding-right: 30px;">
                                        </div>
                                    </div>
                                    <div class="layui-col-xs1">
                                        <div class="layui-form-mid layui-word-aux"
                                             style="color: red !important;padding: 10px !important;">*
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-col-lg6">
                                    <div class="layui-col-xs11">
                                        <label class="layui-form-label">出水浓度</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="econcentration" lay-verify="econcentration"
                                                   autocomplete="off" placeholder="请输入出水浓度"
                                                   class="layui-input" style="padding-right: 30px;">
                                        </div>
                                    </div>
                                    <div class="layui-col-xs1">
                                        <div class="layui-form-mid layui-word-aux"
                                             style="color: red !important;padding: 10px !important;">*
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-col-lg6">
                                    <div class="layui-col-xs11">
                                        <label class="layui-form-label">削减率</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="concentration" lay-verify="concentration"
                                                   autocomplete="off" placeholder="请输入削减率"
                                                   class="layui-input" style="padding-right: 30px;">
                                        </div>
                                    </div>
                                    <div class="layui-col-xs1">
                                        <div class="layui-form-mid layui-word-aux"
                                             style="color: red !important;padding: 10px !important;">*
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-col-lg6">
                                    <div class="layui-col-xs11">
                                        <label class="layui-form-label">排放标准</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="standard" lay-verify="standard"
                                                   autocomplete="off" placeholder="请输入排放标准"
                                                   class="layui-input" style="padding-right: 30px;">
                                        </div>
                                    </div>
                                    <div class="layui-col-xs1">
                                        <div class="layui-form-mid layui-word-aux"
                                             style="color: red !important;padding: 10px !important;">*
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-col-lg6">
                                    <div class="layui-col-xs11">
                                        <label class="layui-form-label">达标情况</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="compliance" lay-verify="compliance"
                                                   autocomplete="off" placeholder="请输入达标情况"
                                                   class="layui-input" style="padding-right: 30px;">
                                        </div>
                                    </div>
                                    <div class="layui-col-xs1">
                                        <div class="layui-form-mid layui-word-aux"
                                             style="color: red !important;padding: 10px !important;">*
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item layui-layout-admin">
                    <div class="layui-footer" style="left: 0;padding: 0px;">
                        <button class="layui-btn" lay-submit lay-filter="*" id="pushButton">立即提交</button>
                    </div>
                </div>
                <input type="hidden" id="username" value="${user.name}">
                <input type="hidden" id="datetime">
                <input type="hidden" id="filetid">
                <input type="hidden" id="filetype" value="shuizhi">
            </form>
        </div>
    </div>
</div>
<script src="<%=request.getContextPath()%>/huazhi/lib/layui-v2.5.5/layui.all.js"></script>
<script src="<%=request.getContextPath()%>/huazhi/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="<%=request.getContextPath()%>/huazhi/lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
<script type="text/html" id="table-files">
    <%-- <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="info">下载</a>--%>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
    layui.use(['form', 'laydate', 'layer','files'], function () {
        var $ = layui.$
            , form = layui.form
            , laydate = layui.laydate
            , layer = layui.layer;
        laydate.render({
            elem:'#datetime',
            type:'datetime',
            value:new Date(),
        });
        laydate.render({
            elem:'#checktime',
            type:'datetime',
        });
        //自定义验证规则
        form.verify({
            cun: function (value, item) {
                if (value === "") {
                    return '请选择检查的村名称';
                }
            },
            operator: function (value, item) {
                if (value === "") {
                    return '请输入检查人名称';
                }
            },
            checktime: function (value, item) {
                if (value === "") {
                    return '请输入检查时间';
                }
            },
            uploadFile: function (value, item) {
                if (value === "") {
                    return '请上传水质检查报告';
                }
            },
            flow: function (value, item) {
                if (value === "") {
                    return '请输入流量';
                }
            },
            ph: function (value, item) {
                if (value === "") {
                    return '请输入pH值';
                }
            },
            do: function (value, item) {
                if (value === "") {
                    return '请输入DO';
                }
            },
            transparency: function (value, item) {
                if (value === "") {
                    return '请输入透明度';
                }
            },
            ss: function (value, item) {
                if (value === "") {
                    return '请输入SS';
                }
            },
            codcr: function (value, item) {
                if (value === "") {
                    return '请输入CODcr';
                }
            },
            bod5: function (value, item) {
                if (value === "") {
                    return '请输入BOD5';
                }
            },
            tp: function (value, item) {
                if (value === "") {
                    return '请输入TP';
                }
            },
            tn: function (value, item) {
                if (value === "") {
                    return '请输入TN';
                }
            },
            hn3N: function (value, item) {
                if (value === "") {
                    return '请输入HN3-N';
                }
            },
            yield: function (value, item) {
                if (value === "") {
                    return '请输入水量';
                }
            },
            iconcentration: function (value, item) {
                if (value === "") {
                    return '请输入进水浓度';
                }
            },
            econcentration: function (value, item) {
                if (value === "") {
                    return '请输入出水浓度';
                }
            },
            concentration: function (value, item) {
                if (value === "") {
                    return '请输入消减率';
                }
            },
            standard: function (value, item) {
                if (value === "") {
                    return '请输入排放标准';
                }
            },
            compliance: function (value, item) {
                if (value === "") {
                    return '请输入达标情况';
                }
            },
        });
        $.ajax({
            type: "get",
            url: "<%=request.getContextPath()%>/rest/base/getSelectVillage",
            dataType: "json",
            async: false,
            success: function (msg) {
                var select = document.getElementById("village");
                $.each(msg.data,function(i,n) {
                    select.options.add(new Option(n.name,n.tid));
                });
                form.render('select','village');
            }
        });

        //第一种方法添加用户
        form.on('submit(*)', function (data) {
            var field = data.field//当前容器的全部表单字段，名值对形式：{name: value}
            var formData = getFormData();
            // formData.set("uploadFile","");
            // var files = $("#uploadfiles").val().split(",");
            // for(var i = 0; i < files.length; i++){
            //     formData.append("uploadFile",files[i]);
            // }
            var index = layer.msg('数据提交中，请稍候', {icon: 16, time: false, shade: 0.6});
            $("#pushButton").addClass("layui-btn layui-btn-disabled").prop("disabled", true);
            $.ajax({
                type: "post",
                url: "<%=request.getContextPath()%>/rest/base/addWatercheck",
                data: formData,
                processData: false,			//对数据不做处理
                dataType: "json",
                cache: false,      			//上传文件不需要缓存
                contentType: false,
                async:false,
                success: function (obj) {
                    setTimeout(function () {
                        layer.close(index);
                        if (obj === true) {
                            layer.msg('添加成功');
                        } else {
                            layer.msg(obj.errorMsg);
                        }
                    }, 2000);
                    setTimeout(function () {
                        var indexs = parent.layer.getFrameIndex(window.name);//获取当前弹出层的层级
                        parent.layer.close(indexs);//关闭弹出层
//                        window.parent.location.reload();//刷新父页面
                    }, 4000);
                }
            });
            return false;
        });
    });
</script>
</body>
</html>